#include "com_tgjorgoski_window_WindowsMethods.h"
#include <windows.h>
#include <stdio.h>

JNIEXPORT void JNICALL Java_com_tgjorgoski_window_WindowsMethods_setWindowAlwaysOnTop
(JNIEnv *env, jclass object, jstring title, jboolean flag)
{
	
	const char *str = env->GetStringUTFChars(title, 0);
	wchar_t buf[128];
	mbstowcs(buf, str, strlen(str)+1);
	(env)->ReleaseStringUTFChars(title, str);

	HWND hwnd;
	hwnd=::FindWindow(NULL,buf);
	if(hwnd==NULL)
	{
		::MessageBox(NULL,buf,L"DLL Run time Error",MB_OK|MB_ICONERROR);
		return ;
	}

	if (flag) {
		SetWindowPos(hwnd,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
		SetWindowLong(hwnd, GWL_EXSTYLE, WS_EX_TOOLWINDOW & ~WS_EX_APPWINDOW);
	} else
		SetWindowPos(hwnd,HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);
	return; 
}